﻿<template>
  <el-input v-bind="$myProps"
            v-on="$myListeners">
    <slot v-for="(slotName) in slotsEnum"
          :name="slotName"
          :slot="slotName">
      <template v-for="(slot,index) in $mySlots[slotName]">
        <form-component :key="index"
                        v-bind="$public.inheritProps(slot)"
                        v-on="$public.inheritListeners(slot)"></form-component>
      </template>
    </slot>
  </el-input>
</template>

<script>
export default {
  components: {
    formComponent: () => import("@/components/component/index"),
  },
  props: {
    value: [String, Number, Boolean],
  },
  data() {
    return {
      slotsEnum: ["prefix", "suffix", "prepend", "append"],
    };
  },
  computed: {
    $myProps() {
      let myProps = this.$public.inheritProps(this);

      //文本域的属性设置缺省值
      if (myProps.type == "textarea") {
        if (!myProps.hasOwnProperty("showWordLimit")) {
          myProps.showWordLimit = true;
        }

        if (!myProps.hasOwnProperty("maxlength")) {
          myProps.maxlength = 200;
        }
      }
      myProps.placeholder = myProps.placeholder || "请输入" + myProps.label;

      return myProps;
    },
    $myListeners() {
      return this.$public.inheritListeners(this);
    },
    $mySlots() {
      let slots = {};

      this.slotsEnum.map((slotName) => {
        slots[slotName] = [];
      });

      return Object.assign(slots, this.$myProps.slots);
    },
  },
};
</script>